package cn.ecnu.mapper;

import cn.ecnu.pojo.Duty;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Set;

@Mapper
public interface DutyMapper {

    // 根据排班ID删除排班
    @Delete("DELETE FROM psychology.duty WHERE duty_id = #{id}")
    int deleteDutyById(@Param("id") Integer dutyId);

    // 获取某个用户某月的排班信息
    @Select("SELECT * FROM psychology.duty WHERE user_id = #{id}" +
            " AND YEAR(duty_date) = #{year}" +
            " AND MONTH(duty_date) = #{month}")
    List<Duty> getDutyByUid(@Param("id") Integer userId, Integer year, Integer month);

    // 获取某天的排班信息
    @Select("SELECT * FROM psychology.duty WHERE DAY(duty_date) = #{day}" +
            " AND YEAR(duty_date) = #{year}" +
            " AND MONTH(duty_date) = #{month}")
    List<Duty> getDutyByDay(Integer year, Integer month, Integer day);

    // 获取某月的排班信息
    @Select("SELECT * FROM psychology.duty WHERE" +
            " YEAR(duty_date) = #{year}" +
            " AND MONTH(duty_date) = #{month}")
    List<Duty> getDutyByMonth(Integer year, Integer month);

    @Insert("INSERT INTO psychology.duty(duty_date, user_id) VALUES (#{dutyDate}, #{userId})")
    int addDuty(Duty duty);
}
